<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglib.jsp"%>
<%@ attribute name="id" type="java.lang.String" required="true" description="编号"%>
<%@ attribute name="name" type="java.lang.String" required="true" description="名称"%>
<%@ attribute name="text" type="java.lang.String" required="true" description="提示文本"%>
<%@ attribute name="url" type="java.lang.String" required="true" description="请求地址"%>
<%@ attribute name="multiple" type="java.lang.Boolean" required="true" description="多选"%>
<%@ attribute name="value" type="java.lang.String" required="false" description="选择值"%>
<%@ attribute name="onchange" type="java.lang.String" required="false" description="改变事件"%>
<%@ attribute name="style" type="java.lang.String" required="false" description="样式"%>
<%@ attribute name="selText" type="java.lang.String" required="true" description="下拉框option显示文本"%>
<%@ attribute name="selValue" type="java.lang.String" required="true" description="下拉框option值"%>
<c:choose>
	<c:when test="${multiple }">
		<select id="${id}" name="${name}" data-placeholder="${text}" class="chosen-select" multiple style="${style}" onchange="${onchange }">
		</select>
	</c:when>
	<c:otherwise>
		<select data-placeholder="${text}" class="chosen-select" ${multiple?'multiple':''  } style="${style}" id="${id}" name="${name}"
			onchange="${onchange }">
		</select>
	</c:otherwise>
</c:choose>
<script type="text/javascript">

$(document).ready(function() {
	$.post("${url}", {}, function(data) {
		$("#${id}").empty();
		$("#${id}").append("<option value=''>${text}</option>");
		var value="${value}";
		for (var i = 0; i < data.length; i++) {
			$("#${id}").append("<option value='"+data[i].${selValue}+ "'   hassubinfo='true' >"+data[i].${selText}+"</option>"); 
		}
		if(''!=value){
			var vArr = value.split(",");
			$("#${id} option").each(function(){
				if(''==this.value){
					return true;  
				} 
				if(value.indexOf(this.value)!=-1){
					this.selected=true;
				}
			});
		}
		$("#${id}").trigger('chosen:updated');
	}, "json");
});

</script>